<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>到货单据查询</title>
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/default/easyui.css"></link>
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/icon.css"></link>
    <script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>

    <script type="text/javascript" src="/static/js/date.js"></script>
    <script src="/static/js/FileSaver.min.js"></script>
    <script src="/static/js/xlsx.full.min.js"></script>
    <script type="text/javascript">

        var url;
        // 屏蔽右键 变为菜单那
        $(function () {
            $(document).bind('contextmenu', function (e) {
                e.preventDefault();
                $('#tree-0').menu('show', {
                    left: e.pageX,
                    top: e.pageY
                });
            });
        });

        //项目列表选择
        function openProjListChoose() {
            $("#projList").dialog("open").dialog("setTitle", "进入项目选择");
            $("#projTree").tree({
                url: '/admin/project/loadProjectTree',
                onLoadSuccess: function (node, data) {
                    $("#tree").tree('expandAll');
                },
                //右键选择树形菜单操作
                onContextMenu: function (e, node) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                    var rootNodes = $("#tree").tree('getRoots');
                    for (var i = 0; i < rootNodes.length; i++) {
                        var theNode = $("#tree").tree('find', rootNodes[i].id);
                        $("#tree").tree('uncheck', theNode.target);
                    }
                    $("#tree").tree('select', node.target);
                    if (node.attributes.state == 2) {
                        $("#tree-2").menu('show', {
                            left: e.pageX,//在鼠标点击处显示菜单
                            top: e.pageY
                        });
                    } else if (node.attributes.state == 1) {
                        $("#tree-1").menu('show', {
                            left: e.pageX,//在鼠标点击处显示菜单
                            top: e.pageY
                        });
                    } else {
                        $('#tree-0').menu('show', {
                            left: e.pageX,//在鼠标点击处显示菜单
                            top: e.pageY
                        });
                    }

                },
                //单击某类别 展示不同详细和按钮选择
                onClick: function (node) {
                    if (node.attributes.state == 2) { // 假如是二级菜单,可以删除
                        $("#projNameList").datagrid('load', {
                            "w_id": node.id
                        });
                    } else if (node.attributes.state == 1) {
                        $("#projNameList").datagrid('load', {
                            "o_id": node.id
                        });
                    }
                }
            });
            loadDataGrid();
        }

        //加载项目数据表格
        function loadDataGrid() {
            $("#projNameList").datagrid({
                //双击事件
                onDblClickRow: function (index, row) {
                    $("#projId").val(row.id);
                    $("#projName").val(row.xiangmumingcheng);
                    $("#projList").dialog("close");
                },
                onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                    $(this).datagrid("clearSelections"); //取消所有选中项
                    $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
                    $('#grid-data').menu('show', {
                        left: e.pageX,//在鼠标点击处显示菜单
                        top: e.pageY
                    });
                    e.preventDefault();  //阻止浏览器自带的右键菜单弹出
                },
            });
        }

        //仓库列表选择
        function openStoreListChoose() {
            $("#storeList").dialog("open").dialog("setTitle", "进入仓库选择");
            $("#storeTree").tree({
                url: '/admin/kufang/loadKufangTree',
                onLoadSuccess: function (node, data) {
                    $("#storeTree").tree('expandAll');
                },
                //右键选择树形菜单操作
                onContextMenu: function (e, node) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                    var rootNodes = $("#tree").tree('getRoots');
                    for (var i = 0; i < rootNodes.length; i++) {
                        var theNode = $("#tree").tree('find', rootNodes[i].id);
                        $("#tree").tree('uncheck', theNode.target);
                    }
                    $("#tree").tree('select', node.target);
                    if (node.attributes.state == 2) {
                        $("#tree-2").menu('show', {
                            left: e.pageX,//在鼠标点击处显示菜单
                            top: e.pageY
                        });
                    } else if (node.attributes.state == 1) {
                        $("#tree-1").menu('show', {
                            left: e.pageX,//在鼠标点击处显示菜单
                            top: e.pageY
                        });
                    } else {
                        $('#tree-0').menu('show', {
                            left: e.pageX,//在鼠标点击处显示菜单
                            top: e.pageY
                        });
                    }

                },
                //单击某类别 展示不同详细和按钮选择
                onClick: function (node) {
                    if (node.attributes.state == 2) { // 假如是二级菜单,可以删除
                        $("#storeNameList").datagrid('load', {
                            "w_id": node.id
                        });
                    } else if (node.attributes.state == 1) {
                        $("#storeNameList").datagrid('load', {
                            "o_id": node.id
                        });
                    }
                }
            });
            loadKufangDataGrid();
        }

        //加载项目数据表格
        function loadKufangDataGrid() {
            $("#storeNameList").datagrid({
                //双击事件
                onDblClickRow: function (index, row) {
                    $("#storeId").val(row.id);
                    $("#storeName").val(row.kufangmingcheng);
                    $("#storeList").dialog("close");
                },
                onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                    $(this).datagrid("clearSelections"); //取消所有选中项
                    $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
                    $('#grid-data').menu('show', {
                        left: e.pageX,//在鼠标点击处显示菜单
                        top: e.pageY
                    });
                    e.preventDefault();  //阻止浏览器自带的右键菜单弹出
                },
            });
        }

        // 查询项目
        function searchProj() {
            $("#projNameList").datagrid('load', {
                "xiangmumingcheng": $("#projSearch").val()
            });
        }

        //查询库房
        function searchStore() {
            $("#storeNameList").datagrid('load', {
                "kufangmingcheng": $("#storeSearch").val()
            })
        }

        //填充项目选择
        function saveProjChoose() {
            var node = $('#projTree').tree('getSelected'); // 获取选中节点
            $("#projId").val(node.id);
            $("#projName").val(node.text);
            $("#projList").dialog("close");
        }

        //填充仓库选择
        function saveStoreChoose() {
            var node = $('#storeTree').tree('getSelected');
            $("#storeId").val(node.id);
            $("#storeName").val(node.text);
            $("#storeList").dialog("close");
        }

        $(document).ready(function () {

            $("#s_btime").datebox("setValue", genLastMonthDayStr()); // 设置上个月日期
            $("#s_etime").datebox("setValue", genTodayStr()); // 设置当前日期

            $('#dg').datagrid({
                onClickRow: function (index, row) {
                    $("#dg2").datagrid({
                        url: '/admin/daohuodan/listDetailsByZId',
                        queryParams: {
                            zongzhangid: row.id
                        },
                        onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                            e.preventDefault(); //阻止浏览器捕获右键事件
                            $(this).datagrid("clearSelections"); //取消所有选中项
                            $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
                            $('#grid-data').menu('show', {
                                left: e.pageX,//在鼠标点击处显示菜单
                                top: e.pageY
                            });
                            e.preventDefault();  //阻止浏览器自带的右键菜单弹出
                        },
                    });
                },
                onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                    $(this).datagrid("clearSelections"); //取消所有选中项
                    $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
                    $('#grid-data').menu('show', {
                        left: e.pageX,//在鼠标点击处显示菜单
                        top: e.pageY
                    });
                    e.preventDefault();  //阻止浏览器自带的右键菜单弹出
                },
            });

        });

        //搜索到货单
        function searchDaohuodan() {
            $('#dg2').datagrid('loadData', {total: 0, rows: []});

            var projName = $("#projName").val();
            var xiangmumingcheng;
            if (projName.length == 0) {
                xiangmumingcheng = "";
            } else {
                xiangmumingcheng = projName;
            }

            var storeName = $("#storeName").val();
            var rukukufang;
            if (storeName.length == 0) {
                rukukufang = "";
            } else {
                rukukufang = storeName;
            }

            $("#dg").datagrid({
                url: '/admin/daohuodan/getSelective',
                queryParams: {
                    wuliaodaohuodanhao: $("#s_danhao").val(),
                    xiangmumingcheng: xiangmumingcheng,
                    rukukufang: rukukufang,

                    s_btime: $("#s_btime").datebox("getValue"),
                    s_etime: $("#s_etime").datebox("getValue")
                },
                onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件                      
                    e.preventDefault(); //阻止浏览器捕获右键事件
                    $(this).datagrid("clearSelections"); //取消所有选中项
                    $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
                    $('#grid-data').menu('show', {
                        left: e.pageX,//在鼠标点击处显示菜单
                        top: e.pageY
                    });
                    e.preventDefault();  //阻止浏览器自带的右键菜单弹出
                },
            });
        }

        //删除到货单
        function deleteDaohuodan() {
            var selectedRows = $("#dg").datagrid("getSelections");
            if (selectedRows.length == 0) {
                $.messager.alert("系统提示", "请选择要删除的到货单！");
                return;
            }
            var ids = new Array();
            if (selectedRows.length > 1) {
                for (var i = 0; i < selectedRows.length; i++) {
                    ids.push(selectedRows[i].id);
                }
            } else if (selectedRows.length == 1) {
                var id = selectedRows[0].id;
                ids.push(id);
            }
            $.messager.confirm("系统提示", "<font color=red>删除到货单后将无法恢复，是否删除？</font>", function (r) {
                if (r) {
                    $.post("/admin/daohuodan/delete", {'ids': ids}, function (result) {
                        if (result.success) {
                            $("#dg").datagrid("reload");
                            $("#dg2").datagrid("reload");
                        } else {
                            $.messager.alert("系统提示", result.errorInfo);
                        }
                    }, "json");
                }
            });
        }

        /*变更报验状态*/
        function changeBaoyanState() {
            var selectedRows = $("#dg").datagrid("getSelections");
            if (selectedRows.length == 0) {
                $.messager.alert("系统提示", "请选择到货单！");
                return;
            }
            var baoyan = selectedRows[0].baoyan;
            var id = selectedRows[0].id;
            $.messager.confirm("系统提示", "<font color=red>报验状态为" + baoyan + ",确定更改现在的状态吗?</font>", function (r) {
                if (baoyan == undefined || baoyan == "" || baoyan == null || baoyan == "未报验") {
                    baoyan = "已报验";
                } else if (baoyan == "已报验") {
                    baoyan = "未报验";
                }
                if (r) {
                    $.post("/admin/daohuodan/update", {
                        'id': id,
                        'baoyan': baoyan
                    }, function (result) {
                        if (result.success) {
                            $("#dg").datagrid("reload");
                            $("#dg2").datagrid("reload");
                        } else {
                            $.messager.alert("系统提示", result.errorInfo);
                        }
                    }, "json");
                }
            })
        }


    </script>
</head>
<body class="easyui-layout" style="margin: 1px">
<div region="north" style="height: 350px;">
    <table id="dg" title="到货单据查询" class="easyui-datagrid" fit=true
           fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
           toolbar="#tb">
        <thead>
        <tr>
            <!--展示到货单主表-->
            <th field="ukyo" align="center" width="30" checkbox="true"></th>
            <th field="id" width="30" align="center" sortable="true">id</th>
            <th field="wuliaodaohuodanhao" width="80" align="center" sortable="true">到货单单号</th>
            <th field="xiangmumingcheng" width="50" align="center" sortable="true">项目名称</th>
            <th field="rukukufang" width="50" align="center" sortable="true">入库库房</th>
            <th field="zhaiyao" width="50" align="center" sortable="true">摘要</th>
            <th field="baoyan" width="50" align="center" sortable="true">报验状态</th>
            <th field="beizhu" width="50" align="center" sortable="true">备注</th>
            <th field="founder" width="50" align="center" sortable="true">创建人</th>
            <th field="createtime" width="70" align="center" sortable="true">创建时间</th>
        </tr>
        </thead>
    </table>

    <div id="tb">
        <div style="padding-bottom: 5px">
            <fieldset style="border-color: #E7F0FF">
                <legend>查询设置</legend>
                &nbsp;单据号：&nbsp;
                <input type="text" id="s_danhao" name="wuliaoshengoudanhao" size="15"
                       onkeydown="if(event.keyCode==13) searchDaohuodan()"/>
                &nbsp;&nbsp;&nbsp;&nbsp;项目选择：<input type="text" id="projName" name="xiangmumingcheng"
                                                    style="width: 90px;" readonly="readonly"
                                                    onclick="openProjListChoose()" required="true"/>
                <input type="hidden" id="projId"/>
                &nbsp;&nbsp;&nbsp;&nbsp;入库库房：<input type="text" id="storeName" name="rukukufang" size="10"
                                                    readonly="readonly" onclick="openStoreListChoose()"
                                                    required="true"/>
                <input type="hidden" id="storeId"/>
                <!-- -->
                <br>
                &nbsp;&nbsp;&nbsp;日期：&nbsp;
                <input id="s_btime" name="s_btime" class="easyui-datebox" editable=false style="width:100px">
                &nbsp;&nbsp;-&nbsp;&nbsp;
                <input id="s_etime" name="s_etime" class="easyui-datebox" editable=false style="width:100px">
                &nbsp;&nbsp;<a href="javascript:searchDaohuodan()" class="easyui-linkbutton" iconCls="icon-search"
                               plain="true">搜索</a>
                &nbsp;&nbsp;<a href="javascript:deleteDaohuodan()" class="easyui-linkbutton" iconCls="icon-remove"
                               plain="true">删除</a>
                <a href="javascript:changeBaoyanState()" class="easyui-linkbutton" iconCls="icon-ok"
                   plain="true">变更报验状态</a>
            </fieldset>
        </div>
    </div>
</div>
<div region="center" style="margin-top: 5px;">
    <table id="dg2" class="easyui-datagrid" fit=true pageList=[10,20,30,40,50,1000000]
           fitColumns="true" rownumbers="true" checkbox="true" pagination="true"
           toolbar="#tbzi">
        <thead>
        <tr>
            <!--展示到货单详细-->
            <th field="ukyo" align="center" width="30" checkbox="true"></th>
            <th field="id" width="60" align="center" sortable="true" hidden="hidden">编号</th>
            <th field="duiyingshengoudanhao" width="80" align="center" sortable="true">申购单号</th>
            <th field="dalei" width="65" align="center" sortable="true">大类</th>
            <th field="wuliaobianma" width="90" align="center" sortable="true">物料编码</th>
            <th field="mingchengguige" width="100" align="center" sortable="true">名称规格</th>
            <th field="number" width="40" align="center" sortable="true">数量</th>
            <th field="danwei" width="40" align="center" sortable="true">单位</th>
            <th field="daohuoshuliang" width="50" align="center" sortable="true">到货数量</th>
            <th field="jiaohuodidian" width="50" align="center" sortable="true">交货地点</th>
            <th field="zhiliangyaoqiu" width="50" align="center" sortable="true">质量要求</th>
            <th field="xuqiuriqi" width="70" align="center" sortable="true">需求日期</th>
            <th field="beizhu" width="50" align="center" sortable="true">备注</th>
            <th field="daohuoshijian" width="70" align="center" sortable="true">到货时间</th>
            <th field="jiagongyigong" width="50" align="center" sortable="true">甲供乙供</th>
            <th field="createtime" width="70" align="center" sortable="true">创建时间</th>
        </tr>
        </thead>
    </table>
    <div id="tbzi">
        <div style="padding-bottom: 5px">
            <fieldset style="border-color: #E7F0FF">
                <legend>明细导出</legend>
                <a href="javascript:void(0)" id="export_excel" iconCls="icon-save" class="easyui-linkbutton"
                   plain="true">保存数据</a>
                - 点击'保存数据'导出下方明细
            </fieldset>
        </div>
    </div>
</div>

<!--查询项目列表-->
<div id="projList" class="easyui-dialog" style="width:800px;height:460px;"
     closed="true" data-options="onClose:function(){$('#s_codeOrProjName').val('');}">
    <div class="easyui-layout" style="width:100%;height:100%;">

        <div region="north" style="height: 50px;">
            <div style="padding-top: 8px;padding-left: 40px;">
                &nbsp;项目名称：&nbsp;<input type="text" id="projSearch" size="30"
                                        onkeydown="if(event.keyCode==13) searchProj()"/>
                <a href="javascript:searchProj()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
            </div>
        </div>
        <div region="west" style="width: 200px" title="项目分类" split="true" data-options="collapsible:false">
            <div style="overflow-x: auto; overflow-y: auto; height: 90%; width:98%;">
                <ul id="projTree" class="easyui-tree" style="padding: 10px"></ul>
            </div>
            <div style="position:absolute;bottom: 10px;left: 15px">
                <a href="javascript:saveProjChoose()" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">选择</a>
                <!--<a id="del" href="javascript:deleteGoodsType()" class="easyui-linkbutton" data-options="iconCls:'icon-remove',disabled:true">删除</a>-->
            </div>
        </div>
        <div region="center">
            <table id="projNameList" title="项目列表" class="easyui-datagrid"
                   fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
                   url="/admin/dproject/getSelective" fit="true" toolbar="#tb4">
                <thead>
                <tr>
                    <th field="id" width="30" hidden=true align="center">编号</th>
                    <th field="xiangmumingcheng" width="150" align="center">项目名称</th>
                    <th field="createtime" width="90" align="left">创建时间</th>

                </tr>
                </thead>
            </table>
            <div id="tb4">
                <div>
                    <a href="javascript:saveProjChoose()" class="easyui-linkbutton" iconCls="icon-ok"
                       plain="true">选择</a>
                </div>
            </div>
        </div>
    </div>
</div>

<!--查询仓库列表-->
<div id="storeList" class="easyui-dialog" style="width:800px;height:460px;"
     closed="true" data-options="onClose:function(){$('#s_codeOrStoreName').val('');}">
    <div class="easyui-layout" style="width:100%;height:100%;">

        <div region="north" style="height: 50px;">
            <div style="padding-top: 8px;padding-left: 40px;">
                &nbsp;仓库名称：&nbsp;<input type="text" id="storeSearch" size="30"
                                        onkeydown="if(event.keyCode==13) searchStore()"/>
                <a href="javascript:searchStore()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
            </div>
        </div>
        <div region="west" style="width: 200px" title="仓库分类" split="true" data-options="collapsible:false">
            <div style="overflow-x: auto; overflow-y: auto; height: 90%; width:98%;">
                <ul id="storeTree" class="easyui-tree" style="padding: 10px"></ul>
            </div>
            <div style="position:absolute;bottom: 10px;left: 15px">
                <a href="javascript:saveStoreChoose()" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">选择</a>
                <!--<a id="del" href="javascript:deleteGoodsType()" class="easyui-linkbutton" data-options="iconCls:'icon-remove',disabled:true">删除</a>-->
            </div>
        </div>
        <div region="center">
            <table id="storeNameList" title="仓库列表" class="easyui-datagrid"
                   fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
                   url="/admin/dkufang/getSelective" fit="true" toolbar="#tb5">
                <thead>
                <tr>
                    <th field="id" width="30" hidden=true align="center">编号</th>
                    <th field="kufangmingcheng" width="150" align="center">仓库名称</th>
                    <th field="createtime" width="90" align="left">创建时间</th>

                </tr>
                </thead>
            </table>
            <div id="tb5">
                <div>
                    <a href="javascript:saveStoreChoose()" class="easyui-linkbutton" iconCls="icon-ok"
                       plain="true">选择</a>
                </div>
            </div>
        </div>
    </div>
</div>


<!--大屏幕上右键datagrid dlg-->
<div id="grid-data" class="easyui-menu" style="width: 80px; display: none;">
    <!--<div id="grid-data-edit" href="javascript:openDetailsModifyDialog()" data-options="iconCls:'icon-edit'">修改</div>-->
    <!--<div id="grid-data-delete" href="javascript:deleteDetails()" data-options="iconCls:'icon-remove'" plain="true">删除-->
    <!--</div>-->
</div>
<!--二级菜单右键弹出-->
<div id="tree-2" class="easyui-menu" style="width: 80px; display: none;">
    <!--<div id="tree-2-delete" href="javascript:deleteType()" data-options="iconCls:'icon-remove'">删除二级菜单</div>-->
</div>
<!--一级菜单右键弹出-->
<div id="tree-1" class="easyui-menu" style="width: 80px; display: none;">
    <!--<div id="tree-1-add-2" href="javascript:openTypeAddDialog()" data-options="iconCls:'icon-add'">添加二级菜单</div>-->
    <!--<div id="tree-1-delete" href="javascript:deleteType()" data-options="iconCls:'icon-remove'">删除一级菜单</div>-->
</div>
<!--树形菜单右键弹出-->
<div id="tree-0" class="easyui-menu" style="width: 80px; display: none;">
    <!--<div id="tree-0-add-1" href="javascript:openTypeAddDialog(0)" data-options="iconCls:'icon-add'">添加一级菜单</div>-->
    <!--<div id="tree-0-refresh" href="javascript:reloadTree()" data-options="iconCls:'icon-reload'">重新加载类别</div>-->
</div>

</body>
<script>
    // 导出excel按钮
    $("#export_excel").click(exportExcel);

    // 导出excel
    function exportExcel() {
        //获得选中记录 多选
        var row = $('#dg2').datagrid('getRows');
        var row = $('#dg').datagrid('getSelections');
        // 去除不需要导出的实体字段
        var deleteKey = ['zhuanye', 'updatetime',
            'zongzhangid', 'sort', 'order'
        ];
        for (var i in row) {
            for (var j in deleteKey) {
                delete row[i][deleteKey[j]];
            }
        }
        if (row) {
            $.messager.confirm('确认按钮', '你确定要导出本页到货明细数据?', function (r) {
                if (r) {
                    downloadExl(row);
                }
            })
        }
    }

    function downloadExl(data, type) {
        var keys = Object.keys(data[0]);
        var firstRow = {};
        keys.forEach(function (item) {
            console.log("item:" + item);
            firstRow[item] = item;
        });
        data.unshift(firstRow);

        var content = {};

        //把json格式的数据转换为excel的行列形式
        var sheetsData = data.map(function (item, rowIndex) {
            return keys.map(function (key, columnIndex) {
                return Object.assign({}, {
                    value: item[key],
                    position: (columnIndex > 25 ? getCharCol(columnIndex) : String.fromCharCode(65 + columnIndex)) + (rowIndex + 1),
                });
            });
        }).reduce(function (prev, next) {
            return prev.concat(next);
        });

        sheetsData.forEach(function (item, index) {
            // content[item.position] = {v: item.value};
            if (item.value == 'id') {
                content[item.position] = {v: '序列号'};
            } else if (item.value == 'duiyingshengoudanhao') {
                content[item.position] = {v: '申购单号'};
            } else if (item.value == 'dalei') {
                content[item.position] = {v: '大类'};
            } else if (item.value == 'wuliaobianma') {
                content[item.position] = {v: '物料编码'};
            } else if (item.value == 'mingchengguige') {
                content[item.position] = {v: '名称规格'};
            } else if (item.value == 'number') {
                content[item.position] = {v: '数量'};
            } else if (item.value == 'danwei') {
                content[item.position] = {v: '单位'};
            } else if (item.value == 'daohuoshuliang') {
                content[item.position] = {v: '到货数量'};
            } else if (item.value == 'jiaohuodidian') {
                content[item.position] = {v: '交货地点'};
            } else if (item.value == 'zhiliangyaoqiu') {
                content[item.position] = {v: '质量要求'};
            } else if (item.value == 'xuqiuriqi') {
                content[item.position] = {v: '需求日期'};
            } else if (item.value == 'beizhu') {
                content[item.position] = {v: '备注'};
            } else if (item.value == 'jiagongyigong') {
                content[item.position] = {v: '甲供乙供'};
            } else if (item.value == 'daohuoshijian') {
                content[item.position] = {v: '到货时间'};
            } else if (item.value == 'createtime') {
                content[item.position] = {v: '创建时间'};
            } else {
                if (item.value == null || item.value == undefined || item.value == 'null') {
                    content[item.position] = {v: ''};  //remember
                } else {
                    content[item.position] = {v: item.value};  //remember
                }
            }
        });

        //设置区域,比如表格从A1到D10,SheetNames:标题
        var coordinate = Object.keys(content);
        var workBook = {
            SheetNames: ["1"],
            Sheets: {
                "1": Object.assign({}, content, {"!ref": coordinate[0] + ":" + coordinate[coordinate.length - 1]}),
            }
        };

        //这里的数据是用来定义导出的格式类型
        var excelData = XLSX.write(workBook, {bookType: "xlsx", bookSST: false, type: "binary"});
        var blob = new Blob([string2ArrayBuffer(excelData)], {type: ""});

        // filename = "石油焦";
        $.messager.prompt("输入框", "请输入保存文件名.", function (filename) {
            if (filename) {
                var nowTime = new Date().toLocaleDateString();
                saveAs(blob, filename + "-到货明细" + nowTime + ".xlsx"); //文件名
            }
        });
    }

    //字符串转字符流
    function string2ArrayBuffer(s) {
        var buf = new ArrayBuffer(s.length);
        var view = new Uint8Array(buf);
        for (var i = 0; i != s.length; ++i) {
            view[i] = s.charCodeAt(i) & 0xFF;
        }
        return buf;
    }

    //将指定的自然数转换为26进制表示. 映射关系: [0-25] -> [A-Z]
    function getCharCol(n) {
        var temCol = "",
            s = "",
            m = 0;
        while (n > 0) {
            m = n % 26 + 1;
            s = String.fromCharCode(m + 64) + s;
            n = (n - m) / 26;
        }
        return s;
    }

</script>
</html>